home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows 95 API Bible
/
Windows 95 API Bible 3 Disc Set.iso
/
Win32 API Bible Book 3 of 3
/
CHAPTE17
/
MIXER1.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-04-29
|
15KB
|
489 lines
#include <windows.h>
#include <stdio.h>
#include "mixer1.h"
#if defined (WIN32)
#define IS_WIN32 TRUE
#else
#define IS_WIN32 FALSE
#endif
#define IS_NT IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
#define IS_WIN32S IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
#define IS_WIN95 (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
HINSTANCE hInst; // current instance
LPCTSTR lpszAppName = "MyApp";
LPCTSTR lpszTitle = "mixerGetDevCaps()";
BOOL RegisterWin95( CONST WNDCLASS* lpwc );
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
MSG msg;
HWND hWnd;
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon (hInstance, lpszAppName);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = lpszAppName;
wc.lpszClassName = lpszAppName;
if ( IS_WIN95 )
{
if ( !RegisterWin95( &wc ) )
return( FALSE );
}
else if ( !RegisterClass( &wc ) )
return( FALSE );
hInst = hInstance;
hWnd = CreateWindow( lpszAppName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0,
CW_USEDEFAULT, 0,
NULL,
NULL,
hInstance,
NULL
);
if ( !hWnd )
return( FALSE );
ShowWindow( hWnd, nCmdShow );
UpdateWindow( hWnd );
while( GetMessage( &msg, NULL, 0, 0) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return( msg.wParam );
}
BOOL RegisterWin95( CONST WNDCLASS* lpwc )
{
WNDCLASSEX wcex;
wcex.style = lpwc->style;
wcex.lpfnWndProc = lpwc->lpfnWndProc;
wcex.cbClsExtra = lpwc->cbClsExtra;
wcex.cbWndExtra = lpwc->cbWndExtra;
wcex.hInstance = lpwc->hInstance;
wcex.hIcon = lpwc->hIcon;
wcex.hCursor = lpwc->hCursor;
wcex.hbrBackground = lpwc->hbrBackground;
wcex.lpszMenuName = lpwc->lpszMenuName;
wcex.lpszClassName = lpwc->lpszClassName;
// Added elements for Windows 95.
//...............................
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName,
IMAGE_ICON, 16, 16,
LR_DEFAULTCOLOR );
return RegisterClassEx( &wcex );
}
#define MSG_LEN 1024
#define LB_TABSTOPS 6
#define MAIN_LB 101
// global variables
//.................
char msg[MSG_LEN+1];
HWND hListBox = NULL;
INT nTabStops[LB_TABSTOPS] = {50, 125, 210, 250, 300, 320};
MMRESULT rc;
MIXERCAPS mxcaps;
UINT nDevId = 0;
HMIXER hmx = NULL;
VOID DisplayMixerLines(HWND hWnd);
VOID GetComponentName(LPMIXERLINE pmxl, LPSTR lpszComponent);
LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch( uMsg )
{
case WM_CREATE :
// Create ListBox
//...............
hListBox = CreateWindow( "LISTBOX", "",
WS_CHILD | LBS_NOTIFY |
WS_VSCROLL | WS_BORDER |
WS_VISIBLE | LBS_NOINTEGRALHEIGHT |
LBS_USETABSTOPS,
0, 0,
0, 0,
hWnd,
(HMENU)MAIN_LB,
hInst,
NULL );
SendMessage(hListBox, LB_SETTABSTOPS, LB_TABSTOPS, (LPARAM)(LPINT)nTabStops);
break;
case WM_SIZE :
MoveWindow( hListBox, 0, 0,
LOWORD( lParam ),
HIWORD( lParam ), TRUE );
break;
case WM_COMMAND :
switch( LOWORD( wParam ) )
{
case IDM_TEST:
{
SendMessage(hListBox, LB_RESETCONTENT, 0, 0);
if (mixerGetNumDevs() == 0)
{
MessageBox(hWnd, "No audio mixer devices found.",
NULL, MB_OK);
DestroyWindow(hWnd); // shut down. app is not of any use.
break;
}
// list device capabilities for first installed
// mixer device
//.............................................
nDevId = 0;
mixerGetDevCaps(nDevId, &mxcaps, sizeof(MIXERCAPS));
sprintf(msg, "Device name: %s\t#Destinations: %ld",
mxcaps.szPname, mxcaps.cDestinations);
SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)msg);
SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)"");
// open first device
//..................
rc = mixerOpen(&hmx, nDevId, (DWORD)hWnd, (DWORD)NULL,
CALLBACK_WINDOW | MIXER_OBJECTF_MIXER);
if (rc != MMSYSERR_NOERROR)
{
MessageBox(hWnd, "Error opening mixer DevId = 0",
NULL, MB_OK);
DestroyWindow(hWnd); // shut down
break;
}
// verify mixer ID
//................
{
UINT nDevIdChk;
rc = mixerGetID((HMIXEROBJ)hmx, &nDevIdChk, MIXER_OBJECTF_HMIXER);
if (rc != MMSYSERR_NOERROR || nDevId != nDevIdChk)
{
MessageBox(hWnd, "Error confirming mixer ID",
NULL, MB_OK);
DestroyWindow(hWnd); // shut down
break;
}
}
// display mixer lines
//....................
DisplayMixerLines(hWnd);
// close mixer
//............
mixerClose(hmx);
}
break;
case IDM_ABOUT :
DialogBox( hInst, "AboutBox", hWnd, About );
break;
case IDM_EXIT :
DestroyWindow( hWnd );
break;
}
break;
case WM_DESTROY :
PostQuitMessage(0);
break;
default :
return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
}
return( 0L );
}
VOID DisplayMixerLines(HWND hWnd)
{
LONG nIndex;
UINT uDest;
UINT uConnect, uConnections;
MIXERLINE mxl;
char lpszComponent[MSG_LEN];
lstrcpy(msg, "Type\tComponent\tName\tLine ID\tFlags\tCtls\tConnections");
SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)msg);
SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)"");
// loop and display all destination components
//............................................
for (uDest = 0; uDest < mxcaps.cDestinations; uDest++)
{
mxl.cbStruct = sizeof(mxl);
mxl.dwDestination = uDest;
// get line info
//..............
rc = mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_DESTINATION);
if (rc != MMSYSERR_NOERROR)
{
sprintf(msg, "mixerGetLineInfo(dst=%u) failed. rc=%u!",
uDest, rc);
MessageBox(hWnd, msg, NULL, MB_OK);
continue;
}
// get line component name
//........................
GetComponentName(&mxl, lpszComponent);
sprintf(msg, "%s\t%-25s\t%-25s\t%.08lXh\t%.08lXh\t%lu\t%lu",
(MIXERLINE_LINEF_ACTIVE & mxl.fdwLine) ? "Dest Active" : "Dest Inactive",
(LPTSTR)lpszComponent,
(LPSTR)mxl.szName,
mxl.dwLineID,
mxl.fdwLine,
mxl.cControls,
mxl.cConnections
);
nIndex = SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)msg);
// loop and display all source components
// for above destination component
//.......................................
uConnections = (UINT)mxl.cConnections;
for (uConnect = 0; uConnect < uConnections; uConnect++)
{
mxl.cbStruct = sizeof(mxl);
mxl.dwDestination = uDest;
mxl.dwSource = uConnect;
rc = mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_SOURCE);
if (rc != MMSYSERR_NOERROR)
{
sprintf(msg, "mixerGetLineInfo(src=%u) failed. rc=%u!",
uConnect, rc);
MessageBox(hWnd, msg, NULL, MB_OK);
continue;
}
// get line component name
//........................
GetComponentName(&mxl, lpszComponent);
sprintf(msg, "%s\t%-25s\t%-25s\t%.08lXh\t%.08lXh\t%lu\t%lu",
(MIXERLINE_LINEF_ACTIVE & mxl.fdwLine) ? " Src Active" : " Src Inactive",
(LPTSTR)lpszComponent,
(LPSTR)mxl.szName,
mxl.dwLineID,
mxl.fdwLine,
mxl.cControls,
mxl.cConnections
);
nIndex = SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)msg);
SendMessage(hListBox, LB_SETITEMDATA, (WPARAM)nIndex, (LPARAM)mxl.dwLineID);
}
}
}
VOID GetComponentName(LPMIXERLINE pmxl, LPSTR lpszComponent)
{
// translate component name
//.........................
if (pmxl->fdwLine & MIXERLINE_LINEF_SOURCE)
{
// source components
//..................
switch (pmxl->dwComponentType)
{
case MIXERLINE_COMPONENTTYPE_SRC_ANALOG:
lstrcpy(lpszComponent, "Analog");
break;
case MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY:
lstrcpy(lpszComponent, "Auxiliary");
break;
case MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC:
lstrcpy(lpszComponent, "Compact Disc");
break;
case MIXERLINE_COMPONENTTYPE_SRC_DIGITAL:
lstrcpy(lpszComponent, "Digital");
break;
case MIXERLINE_COMPONENTTYPE_SRC_LINE:
lstrcpy(lpszComponent, "Line Level");
break;
case MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE:
lstrcpy(lpszComponent, "Microphone");
break;
case MIXERLINE_COMPONENTTYPE_SRC_PCSPEAKER:
lstrcpy(lpszComponent, "PC Speaker");
break;
case MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER:
lstrcpy(lpszComponent, "Synthesizer");
break;
case MIXERLINE_COMPONENTTYPE_SRC_TELEPHONE:
lstrcpy(lpszComponent, "Telephone");
break;
case MIXERLINE_COMPONENTTYPE_SRC_UNDEFINED:
lstrcpy(lpszComponent, "Undefined");
break;
case MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT:
lstrcpy(lpszComponent, "Wave Out");
break;
default:
lstrcpy(lpszComponent, "INVALID");
break;
}
}
else
{
// destination components
//.......................
switch (pmxl->dwComponentType)
{
case MIXERLINE_COMPONENTTYPE_DST_DIGITAL:
lstrcpy(lpszComponent, "Digital");
break;
case MIXERLINE_COMPONENTTYPE_DST_HEADPHONES:
lstrcpy(lpszComponent, "Headphones");
break;
case MIXERLINE_COMPONENTTYPE_DST_LINE:
lstrcpy(lpszComponent, "Line Level");
break;
case MIXERLINE_COMPONENTTYPE_DST_MONITOR:
lstrcpy(lpszComponent, "Monitor");
break;
case MIXERLINE_COMPONENTTYPE_DST_SPEAKERS:
lstrcpy(lpszComponent, "Speakers");
break;
case MIXERLINE_COMPONENTTYPE_DST_TELEPHONE:
lstrcpy(lpszComponent, "Telephone");
break;
case MIXERLINE_COMPONENTTYPE_DST_UNDEFINED:
lstrcpy(lpszComponent, "Undefined");
break;
case MIXERLINE_COMPONENTTYPE_DST_VOICEIN:
lstrcpy(lpszComponent, "Voice Recognition");
break;
case MIXERLINE_COMPONENTTYPE_DST_WAVEIN:
lstrcpy(lpszComponent, "Wave Input");
break;
default:
lstrcpy(lpszComponent, "INVALID");
break;
}
}
}
LRESULT CALLBACK About( HWND hDlg,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return (TRUE);
case WM_COMMAND:
if ( LOWORD(wParam) == IDOK
|| LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, TRUE);
return (TRUE);
}
break;
}
return (FALSE);
}